#include"comm.hpp"
#include"myfifo.hpp"
#include<unistd.h>

int main()
{
    //获取key
    key_t key = GetshmKeyOrDie();
    std::cout<<"key:"<<ToHex(key)<<std::endl;
    //创建共享内存
    int shmid = Createshm(key,defaultsize);
    std::cout<<"shmid:"<<shmid<<std::endl;
    //将共享内存和进程进行关联
    char *addr = (char*)shmAttach(shmid);
    std::cout<<"挂接成功,addr:"<<ToHex((uint64_t)addr)<<std::endl;
    fifo f;
    Sync s;
    s.OpenRead();
    for(;;)
    {
        if(!s.Wait())
        {
            break;
        }
        cout<<"读取内容："<<addr<<endl;
    }


    //去关联
    shmDetach(addr);
    std::cout<<"去关联成功,addr:"<<ToHex((uint64_t)addr)<<std::endl;
    //删除共享内存
    DeleteShm(shmid);
    return 0;
}